/**
 * Created by mFramework.
 * User: Mauro
 * Date: 2/05/11
 * Time: 17:05
 */
jQuery(document).ready(function() {
    $("#formUsers").validate({
        rules: {
            email: {
				required    :   true,
				email       :   true
			},
            password: {
                minlength   :   5
            },
            confirm_password: {
                minlength   :   5,
                equalTo     :   "#password"
            },
            token: {
                required    :   true,
                minlength   :   25
            }
        }
    });

    if($("#token").val()=="")
        generateToken();
});

function generateToken() {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 25;
    var randomstring = '';
    for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
    $("#token").val(randomstring);
}

function activePassword( check ) {
    $("#editPassword").toggle('slow',function(){
        if(check)
        {
            $("#password").attr('disabled','');
            $("#confirm_password").attr('disabled','');
        }
        else
        {
            $("#password").attr('disabled','disabled');
            $("#confirm_password").attr('disabled','disabled');
        }
    });
}